Skip to content

fix: handle NPE when NotifyCenter.INSTANCE is null during graceful shutdown#4284

Open
Senrian wants to merge 1 commit intoalibaba:2025.1.xfrom
Senrian:fix/nacos-graceful-shutdown-npe-1774180457
Open

fix: handle NPE when NotifyCenter.INSTANCE is null during graceful shutdown#4284
Senrian wants to merge 1 commit intoalibaba:2025.1.xfrom
Senrian:fix/nacos-graceful-shutdown-npe-1774180457

Conversation

@Senrian
Copy link

@Senrian Senrian commented Mar 22, 2026

What

When Spring context closes, NacosGracefulShutdownDelegate.doGracefulShutdown() calls autoServiceRegistration.stop() which internally deregisters subscribers from Nacos NotifyCenter. However, if the Nacos client shutdown hooks have already destroyed NotifyCenter.INSTANCE, this results in:

java.lang.NullPointerException: Cannot read field "sharePublisher" because "NotifyCenter.INSTANCE" is null

Fix

Add explicit NullPointerException catch in doGracefulShutdown() and log a warning instead of propagating, since this NPE is safe to ignore during shutdown when the NotifyCenter has already been cleaned up.

Testing

The existing test sameContextShouldTriggerStop and other tests in NacosGracefulShutdownDelegateTests continue to pass since they mock autoServiceRegistration.stop() to not throw NPE.

Fixes #4283

…utdown

When Spring context closes, if Nacos client shutdown hooks have already
destroyed NotifyCenter.INSTANCE, autoServiceRegistration.stop() throws NPE.
Catch NPE explicitly and log a warning instead of propagating.

Fixes alibaba#4283
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants